package com.lk.spring.boot.sample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.http.HttpStatus;

/**
 * 
 *spring boot 启动入口
 * spring-boot ，自带了Tomcat
 * 从此入口启动后，页面看通过localhost:8080/+控制层路径地址，便可访问
 * 
 */
@SpringBootApplication
//@ComponentScan("com.lk.spring.boot.sample")
//@ImportResource(locations="classpath*:/applicatio-context.xml")//使用xml方式配置spring自动扫描包，mybatis
public class App 
{
    public static void main( String[] args )
    {
        SpringApplication.run(App.class, args);
    }
    /**
     * 错误处理方式一
     * @return
     */
    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer(){
    	return (container->{
    		ErrorPage error401Page =new ErrorPage(HttpStatus.UNAUTHORIZED,"/401.html");
    		ErrorPage error404Page=new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
    		ErrorPage error500Page=new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");
    		
    		container.addErrorPages(error401Page,error404Page,error500Page);
    	});
    }
}
